package pattern.config;

import cn.hutool.json.JSONUtil;
import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * minio服务器配置
 * @author Simon
 */
@Configuration
@Slf4j
public class MinioConfig {
	
	@Value("${minio.url}")
    private String url;
    @Value("${minio.accessKey}")
    private String accessKey;
    @Value("${minio.secretKey}")
    private String secretKey;
    
    @Bean
    public MinioClient getMinioClient() {
        if(StringUtils.isAnyBlank(url,accessKey,secretKey)){
            log.error("minio client 服务端链接未配置");
        }
        var build = MinioClient.builder().endpoint(url)
                .credentials(accessKey, secretKey).build();
        log.info("minio client init info :{0}"+JSONUtil.toJsonStr(build));
        return build;
    }
    
}
